package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.app.DownLoadUserReviewDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserReviewDataCommand;
import com.cskaoyan.wordmemorize.service.UserReviewService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * APP用户复习相关接口控制器
 */
@RestController
@RequestMapping("/user/review")
@Tag(name = "APP用户特权相关接口")
public class AppUserReviewController {

    @Resource
    private UserReviewService userPrivilegeService;

    @PostMapping("/voc")
    @Operation(summary = "添加用户的单词复习数据(参数为用户已选单词的id集合)", description = "用于用户在点击加入记忆的时候，添加用户的单词复习数据")
    public Result<Void> addUserRovRev(@RequestBody List<Long> vocIds) {
        // 获取当前登录用户的ID
        Long userId = StpKit.USER.getLoginIdAsLong();
        // 调用Service层
        userPrivilegeService.addUserRovRev(vocIds, userId);
        return Result.ok();
    }

    @GetMapping("/data")
    @Operation(summary = "下载用户的所有单词复习数据", description = "用于用户在登录时下载自己的复习数据志(登出之后登录)")
    public Result<DownLoadUserReviewDTO> downloadUserReviewData(PageRequest pageRequest) {
        // 获取当前登录用户的ID
        Long userId = StpKit.USER.getLoginIdAsLong();
        // 调用Service层
        DownLoadUserReviewDTO downLoadUserReviewDTO = userPrivilegeService.downloadUserReviewData(pageRequest, userId);
        return Result.ok(downLoadUserReviewDTO);
    }


    @PostMapping("/data")
    @Operation(summary = "同步用户的复习数据", description = "用于APP同步用户的复习数据")
    public Result<Void> synchronizeUserReviewData(@RequestBody UserReviewDataCommand command) {
        // 获取当前登录用户的ID
        Long userId = StpKit.USER.getLoginIdAsLong();
        // 调用Service层
        userPrivilegeService.synchronizeUserReviewData(command, userId);
        return Result.ok();
    }
}
